from selenium import webdriver
from selenium.webdriver.common.by import By
import  time

driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
driver.find_element(By.ID,'kw').send_keys('python')
driver.find_element(By.ID,'su').click()

# 第一种  滚动到底部
time.sleep(2)
js1 = 'window.scrollTo(0,document.body.scrollHeight)'
driver.execute_script(js1)

#滚动到最上面
time.sleep(2)
js2 ='window.scrollTo(0,0)'
driver.execute_script(js2)



# 第二种 滚动到最上面
time.sleep(2)
js3 = 'window.scrollTo({left:0,top:document.body.scrollHeight,behavior:"smooth"})'
driver.execute_script(js3)
# 滚动到底部
time.sleep(2)
driver.execute_script(js2)

# 聚焦
time.sleep(2)
target=driver.find_element(By.PARTIAL_LINK_TEXT,'菜鸟教程')
driver.execute_script('arguments[0].scrollIntoView();',target)



time.sleep(3)
driver.quit()



